<?php
require_once '../include/common.inc.php';
require_once '../include/upfile.class.php';

if (!checkAdmin()) {
	header("LOCATION:index.php");
	exit;
}
$menu_index = 1;
$page_title = 'JANSEN';
$guide_message = 'Product | Style/Period';
$out_ary = array();
$sql_where = '';

getMyParam('action');
getMyParam('description');
getMyParam('name');
getMyParam('ispublish');
getMyParam('ids');


if ($action != "") 
{
	$description= htmlentities($description,ENT_QUOTES,"UTF-8");
	if ($action == 'add') 
	{
		if(!empty($name))
		{
			$sql = "INSERT INTO `p_style`(`name`,`description`,`ispublish`,`createtime`) VALUES('".$name."','".$description."','".$ispublish."','".date("yyyy-mm-dd H:i:s")."')";	
			$db->query($sql);
			
			//Write to cache file
			style_cache();
		}
		header("LOCATION:" . $PHP_SELF);
	}
	elseif($action == 'edit') 
	{
		getMyParam('id');
		
		$sql = "UPDATE `p_style` SET `name`='".$name."', `description`='".$description."', `ispublish`=".$ispublish." WHERE `id`=$id";	
		$db->query($sql);	
		
		//Write to cache file
		style_cache();
	}
	elseif($action == 'del') {
		getMyParam('id');
		if (is_numeric($id) && $id > 0) {
						
			$sql = "DELETE FROM `p_style` WHERE `id` = '" . $id . "'";
			$db->query($sql);
			
			//Write to cache file
			style_cache();
		}
		
		goFromPage();
	}
	
}


$ed_description="";
$ed_strOption="";
$ed_id="";
$ed_name="";
$statusEd='style="display:none"';

if(isset($ids)&&ids!="")
{
 	$sql = "SELECT * FROM `p_style` WHERE `id` = '$ids'";
	$rsedit = $db->get_one($sql);	
	if($rsedit["ispublish"]==1)
		$strOption = '<option value="1" selected>Yes</option><option value="0">No</option>';
	else
		$strOption = '<option value="1">Yes</option><option value="0" selected>No</option>';
		
		$ed_description=html_entity_decode($rsedit["description"],ENT_QUOTES,"UTF-8");
		$ed_id=$rsedit["id"];
		$ed_name=$rsedit["name"];	
		$statusEd='';
}



// *** page code start ***

if ($action == "search" && trim($Search)  != "" && trim($Search)  != "Enter Name ...") {
	$sql_where = " `name` LIKE '%$Search%'";
}
if($sql_where !='') $sql_where = " WHERE ".$sql_where;

$page_url = 'p_style.php?';

$sql = "SELECT `id` FROM `p_style`".$sql_where;
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);

$ppp = 100;
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
	$start_limit = 0;
	$page = 1;
}

$page_show = getPageStr($sql_all_num, $page, $ppp, $page_url);

// *** page code end ***

$sql = "SELECT `id`, `name`,`description`,`ispublish`, `createtime` FROM `p_style`".$sql_where." ORDER BY `createtime` ASC LIMIT $start_limit, $ppp";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	$rs["description"]=html_entity_decode($rs["description"],ENT_QUOTES,"UTF-8");
	$out_ary[] = $rs;
}

$debug = 1;
debuginfo();

include_once(JANSEN_ROOT . 'admin/menu_list.php');
require_once PrintEot('a_header');
require_once PrintEot('a_p_style');
require_once PrintEot('a_footer');
?>